﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ZaxLib.Web.Writers.Nodes;

namespace ZaxLib.Web.UI.WebControls
{
	[DefaultProperty("Text")]
	[ToolboxData("<{0}:DragItem runat=server></{0}:DragItem>")]
	public class DragItem : ZaxControl
	{
		#region Control Writers

		protected override void ControlWrite(HtmlTextWriter writer)
		{
			base.ControlWrite(writer);
			writer.AddAttribute(HtmlTextWriterAttribute.Id, ID);
			if (CssClass.Trim().Length > 0)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClass);
			}
			writer.RenderBeginTag(HtmlTextWriterTag.Div);
			writer.WriteLine(Text);
			writer.RenderEndTag();

			INode node = CodeWriter.CreateReadyFunction();
			//CodeWriter.AddChild(String.Format("'input[id$={0}]'", ID), node).Selector();
			CodeWriter.AddChild(ID, node).Selector();
			CodeWriter.AddChild("draggable").Joined();
			node = CodeWriter.AddParam("").ObjectDef();
			CodeWriter.AddParam("revert", "\"invalid\"", node).VarDef();

		}

		#endregion

		#region Render Methods

		protected override void RenderContents(HtmlTextWriter writer)
		{
			base.RenderContents(writer);
		}

		#endregion
	}
}
